<?php


namespace App\Models\Material;

use App\Models\Workflow\WorkflowLog;
use App\Models\Workflow\WorkflowProcess;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;

class TyreOutMaterial extends Model
{
    protected $table = 'akbus_material_tyre_out';

    protected $fillable = [
        'odd_num',
        'out_time',
        'supplier',
        'handler_user_id',
        'fleet',
        'node',
        'process_state',
        'user_id',
        'del_state',
        'created_at',
        'updated_at',
    ];

    /**
     * 不可批量赋值的属性。
     *
     * @var array
     */
    protected $guarded = [
    ];

    /**
     * 类型转化
     *
     * @var array
     */
    protected $casts = [
    ];

    /**
     * 隐藏的字段
     *
     * @var array
     */
    protected $hidden = [
    ];
    /**
     * 获取表名
     *
     * @return mixed
     */
    public static function getTableName()
    {
        return with(new self)->getTable();
    }

    /**
     * 出库详情
     */
    public function tyreOutMaterialDetail(): HasMany
    {
        return $this->hasmany(TyreOutMaterialDetail::class, 'tyre_out_id');
    }
    /**
     *单据现在状态
     *
     * @return HasOne
     */
    public function process(): HasOne
    {
        return $this->hasOne(WorkflowProcess::class, 'apply_id');
    }

    /**
     * 单据审核历史记录
     *
     * @return HasMany
     */
    public function logs(): HasMany
    {
        return $this->hasmany(WorkflowLog::class, 'apply_id');
    }
}
